<?php
/**
* 地区管理（省份城市县区）
*/
namespace Admin\Controller;

class AreaController extends CommonController{
	public  $exec_comfunc  = 'index,add,edit,delete';//index,add,edit,delete

	//地区列表
	public function index(){
		$parentid   = $this->_get('parentid',0);
		$upparentid = $this->_get('upparentid',0);
		$type       = $this->_get('type',0);
		
		$this->assign('parentid',$parentid);
		$this->assign('type',$type);
		$this->assign('upparentid',$upparentid);

		$this->_boolean_field = array('no');
		$where['parentid'] = $parentid;
		parent::index('',$where,'order_id,id');
	}
	//添加地区
	public function add(){
		$parentid = $this->_get('parentid',0);
		$type     = $this->_get('type',0);

		$data['type'] = $type+1;

		$this->assign('parentid',$parentid);
		parent::add('',$data,U('index',array('parentid'=>$parentid)));
	}
	//删除
	public function delete(){
		$id = $this->_get('id','对不起，ID不能为空！');
		if(D('Area')->where("parentid='$id'")->count()){
			$this->error('对不起，还有下级内容，无法删除！');
		}else{
			D('Area')->where("id='$id'")->delete();
			$this->success('删除成功！');
		}
	}
	//获取地区数据
	public function get_area_list(){
		$where['parentid'] = $this->_get('parentid');
		$list = D('Area')->where($where)->order('order_id,id')->select();
		$data['list'] = $list;

		$this->success('获取数据成功！', '', $data);
	}
}
?>